const fs = require('fs')
const path = require('path')
let size = 0
// console.log(path.resolve('../'))
// console.log(fs.statSync(path.resolve('../README.md')).size)
// console.log(fs.readdirSync(path.resolve('../')))
// console.log(fs.statSync('../').isFile())
getFiles('../')
console.log('文件总大小（字节）:', size)


function getFiles (dir) {
    const stat = fs.statSync(dir)
    if (stat.isDirectory()) {
        //判断是不是目录
        const dirs = fs.readdirSync(dir)
        dirs.forEach(value => {
            // console.log('路径',path.resolve(dir,value));
            getFiles(path.join(dir, value))
        })
    } else if (stat.isFile()) {
        //判断是不是文件
        console.log('文件名称', dir);
        size += stat.size
    }
    
}